home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / AWARE_H.PAK / DBMISC.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  10KB  |  197 lines

  1. //--------------------------------------------------------
  2. // DBMISC.H
  3. // Copyrights (C) 1996 Borland International
  4. // All Rights Reserved
  5. //--------------------------------------------------------
  6.  
  7. #if !defined(DBMISC_H_)
  8. #define DBMISC_H_
  9.  
  10. #include <owl/vbxctl.h>
  11. #include <vdbt/bdto.h>
  12.  
  13.  
  14. //
  15. // Mangle the class and function names so we can have mulitpale versions of the
  16. // same classes and functions in one .LIB file.
  17. //
  18. #if defined( __DLL__ ) && ! defined( __FLAT__ )
  19. #  if defined( _RTLDLL )
  20. #    define GetSource       dGetSource
  21. #    define SetSource       dSetSource
  22. #    define GetField        dGetField
  23. #    define SetField        dSetField
  24. #    define GetStrings      dGetStrings
  25. #    define SetStrings      dSetStrings
  26. #    define Getstring       dGetstring
  27. #    define Setstring       dSetstring
  28. #    define ThrowException  dThrowException
  29. #    define DBEqualOperator dDBEqualOperator
  30. #  else _RTLDLL
  31. #    define GetSource       uGetSource
  32. #    define SetSource       uSetSource
  33. #    define GetField        uGetField
  34. #    define SetField        uSetField
  35. #    define GetStrings      uGetStrings
  36. #    define SetStrings      uSetStrings
  37. #    define Getstring       uGetstring
  38. #    define Setstring       uSetstring
  39. #    define ThrowException  uThrowException
  40. #    define DBEqualOperator uDBEqualOperator
  41. #  endif _RTLDLL
  42. #elif defined( _RTLDLL )
  43. #  define GetSource       iGetSource
  44. #  define SetSource       iSetSource
  45. #  define GetField        iGetField
  46. #  define SetField        iSetField
  47. #  define GetStrings      iGetStrings
  48. #  define SetStrings      iSetStrings
  49. #  define Getstring       iGetstring
  50. #  define Setstring       iSetstring
  51. #  define ThrowException  iThrowException
  52. #  define DBEqualOperator iDBEqualOperator
  53. #endif
  54.  
  55. //------------------------------------------------------------------------------
  56. // Foreward Declarations
  57. //------------------------------------------------------------------------------
  58. extern TDataSource* PASCAL GetSource( TVbxControl*, LPCSTR, TDataSource* );
  59. extern TDataSource* PASCAL SetSource( TVbxControl*, LPCSTR, TDataSource* );
  60. extern TField*      PASCAL GetField( TVbxControl*, int, TDataSource*, TField* );
  61. extern TField*      PASCAL SetField( TVbxControl*, int, TField* );
  62. extern TStrings*    PASCAL GetStrings( TVbxControl*, int, TStrings* );
  63. extern TStrings*    PASCAL SetStrings( TVbxControl*, int, TStrings* );
  64. extern string*      PASCAL Getstring( TVbxControl*, int, string* );
  65. extern string*      PASCAL Setstring( TVbxControl*, int, string* );
  66. extern void         PASCAL ThrowException( LPCSTR );
  67. extern bool         DBEqualOperator( TGenericTableEntry __RTFAR&
  68.                                          , TEventHandler::TEventInfo&);
  69. extern "C"  extern FAR PASCAL HCTL VBGetDataSourceControl( HCTL, BOOL* );
  70. extern "C"  extern FAR PASCAL HCTL VBXFindControl( HWND, LPCSTR );
  71.  
  72.  
  73. //------------------------------------------------------------------------------
  74.  
  75. #ifdef __FLAT__
  76. #  define Debug( x ) { char Msg[ 128 ]; wsprintf x; \
  77.                        ::MessageBox( 0, Msg, "Debug", MB_OK ); }
  78. #else
  79. #  define Debug( x ) { char Msg[ 128 ]; wsprintf x; OutputDebugString( Msg ); }
  80. #endif
  81.  
  82. #define DEFINE_DB_RESPONSE_TABLE1(cls, base)                  \
  83. bool  cls::Find( TEventInfo& eventInfo, TEqualOperator equal )\
  84. {                                                             \
  85.   eventInfo.Object = (GENERIC*)this;                          \
  86.   return SearchEntries( (TGenericTableEntry __RTFAR*)__entries\
  87.                       , eventInfo, ::DBEqualOperator )        \
  88.       || base::Find( eventInfo, equal );                      \
  89. }                                                             \
  90. DEFINE_RESPONSE_TABLE_ENTRIES(cls)
  91.  
  92.  
  93. #define DECLARE_CONSTRUCTORS( TDBClass )                                \
  94.   public:                                                               \
  95.     TDBClass( TWindow*, int, LPCSTR, int, int, int, int, TModule*x=0 ); \
  96.     TDBClass( TWindow*, int, TModule*x=0 )
  97.  
  98. #define DEFINE_DB_PROP_STRING( cls, _cls, name )                    \
  99. inline string* cls::pr##name::Set()                                 \
  100. {                                                                   \
  101.   return p = ::Setstring( DBOUTER( name ), Prop##_cls##_##name, p );\
  102. }                                                                   \
  103. inline string* cls::pr##name::Get()                                 \
  104. {                                                                   \
  105.   return p = ::Getstring( DBOUTER( name ), Prop##_cls##_##name, p );\
  106. }
  107.  
  108. #define DEFINE_DB_PROP_SOURCE( cls, name )            \
  109. inline TDataSource* cls::pr##name::Set()              \
  110. {                                                     \
  111.   return p = ::SetSource( DBOUTER( name ), #name, p );\
  112. }                                                     \
  113. inline TDataSource* cls::pr##name::Get()              \
  114. {                                                     \
  115.   return p = ::GetSource( DBOUTER( name ), #name, p );\
  116. }
  117.  
  118. #define DEFINE_DB_PROP_DATASOURCE( cls ) \
  119.         DEFINE_DB_PROP_SOURCE( cls, DataSource )
  120.  
  121. #define DEFINE_DB_PROP_LOOKUPSOURCE( cls ) \
  122.         DEFINE_DB_PROP_SOURCE( cls, LookupSource )
  123.  
  124. #define DEFINE_DB_PROP_FIELD( cls, _cls, name )                                \
  125. inline TField* cls::pr##name##Field::Get()                                     \
  126. {                                                                              \
  127.   cls *c = DBOUTER( name##Field );                                             \
  128.                                                                                \
  129.   return p = ::GetField( c, Prop##_cls##_##name##Field, c->##name##Source, p );\
  130. }                                                                              \
  131. inline TField* cls::pr##name##Field::Set()                                     \
  132. {                                                                              \
  133.   return p = ::SetField( DBOUTER( name##Field ), Prop##_cls##_##name##Field, p );\
  134. }
  135.  
  136. #define DEFINE_DB_PROP_DATAFIELD( cls, _cls )   \
  137.         DEFINE_DB_PROP_FIELD( cls, _cls, Data )
  138. #define DEFINE_DB_PROP_LOOKUPFIELD( cls, _cls ) \
  139.         DEFINE_DB_PROP_FIELD( cls, _cls, Lookup )
  140.  
  141.  
  142. //----------------------------------------------------------------------------
  143. #define DECLARE_DB_PROP_RWS( cls, name )                                     \
  144.   public:                                                                    \
  145.     struct _DBAWARECLASS pr##name : TDBPropertyRwx< TStrings >               \
  146.     {                                                                        \
  147.       pr##name()                                                             \
  148.       : OnChangeSink( TStringsNotify_MFUNCTOR( *this, &pr##name::OnChange ) )\
  149.       {                                                                      \
  150.       }                                                                      \
  151.                                                                              \
  152.       struct pr##name& operator=( struct pr##name& arg )                     \
  153.       {                                                                      \
  154.         *this = (TStrings*)arg;                                              \
  155.         return *this;                                                        \
  156.       }                                                                      \
  157.       TStrings* operator=( TStrings* arg )                                   \
  158.       {                                                                      \
  159.         return TDBPropertyRwx< TStrings >::operator=( arg );                 \
  160.       }                                                                      \
  161.       TStrings& operator=( TStrings& arg )                                   \
  162.       {                                                                      \
  163.         return TDBPropertyRwx<TStrings>::operator=( arg );                   \
  164.       }                                                                      \
  165.       TStrings* Get();                                                       \
  166.       TStrings* Set();                                                       \
  167.                                                                              \
  168.       void OnChange( TStringsNotifySink& sink, TStrings& sender )            \
  169.       {                                                                      \
  170.         *this = &sender;                                                     \
  171.         sink.Pass( sender );                                                 \
  172.       }                                                                      \
  173.                                                                              \
  174.       TStringsNotifySink OnChangeSink;                                       \
  175.     } name;                                                                  \
  176.     friend struct pr##name
  177.  
  178. #define DEFINE_DB_PROP_TSTRINGS( cls, _cls, name )                           \
  179. inline TStrings* cls::pr##name::Get()                                        \
  180. {                                                                            \
  181.   if( p )                                                                    \
  182.     p->OnChangeSource -= OnChangeSink;                                       \
  183.   if( (p = ::GetStrings( DBOUTER( name ), Prop##_cls##_##name, p )) != NULL )\
  184.     p->OnChangeSource += OnChangeSink;                                       \
  185.   return p;                                                                  \
  186. }                                                                            \
  187. inline TStrings* cls::pr##name::Set()                                        \
  188. {                                                                            \
  189.   if( p )                                                                    \
  190.     p->OnChangeSource -= OnChangeSink;                                       \
  191.   if( (p = ::SetStrings( DBOUTER( name ), Prop##_cls##_##name, p )) != NULL )\
  192.     p->OnChangeSource += OnChangeSink;                                       \
  193.   return p;                                                                  \
  194. }
  195.  
  196. #endif DBMISC_H_
  197.